//
//  NSObject+Property.m
//  Runtime
//
//  Created by apple on 2017/3/30.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "NSObject+Property.h"

@implementation NSObject (Property)


+ (void) getPropertyCodeWithDict:(NSDictionary *)dict{

    
    
    NSMutableString *arrayM = [NSMutableString string];
    //遍历整个字典
    [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull propertyName, id  _Nonnull value, BOOL * _Nonnull stop) {
        
        //NSLog(@"%@ %@",propertyName,[value class]);

        NSString *code;
        
        if ([value isKindOfClass:NSClassFromString(@"__NSCFString")]) {
            
            code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",propertyName];
            
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){
            
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSNumber *%@;",propertyName]
            ;
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFArray")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",propertyName]
            
            ;
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",propertyName]
            
            ;
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",propertyName]
            
            ;
        }else if(([value isKindOfClass:NSClassFromString(@"NSNull")])){
        
            //code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",propertyName];
        
            NSLog(@"字典存在空值 NSNull,无法判断类型");
        }
        
        [arrayM appendFormat:@"\n%@\n",code];
    }];
    
    NSLog(@"%@",arrayM);
    
}

@end
